﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using MethodCaching;

namespace SampleLibrary
{
    [EnableMethodCaching]
    public class SampleClass : ISampleClass
    {
        [Cached]
        public int GetValue()
        {
            return 0;
        }

        [Cached]
        public int GetValue(int input)
        {
            return input;
        }

        [Cached]
        public int GetValue(int input1, int input2)
        {
            return input1 + input2;
        }

        [Cached]
        public int GetValue(int input1, int input2, int input3)
        {
            return input1 + input2 + input3;
        }

        [Cached]
        public int GetValue(int input1, int input2, int input3, int input4)
        {
            return input1 + input2 + input3 + input4;
        }

        [Cached]
        public static int StaticGetValue()
        {
            return 0;
        }

        [Cached]
        public static int StaticGetValue(int input)
        {
            return input;
        }

        [Cached]
        public static int StaticGetValue(int input1, int input2)
        {
            return input1 + input2;
        }

        [Cached]
        public static int StaticGetValue(int input1, int input2, int input3)
        {
            return input1 + input2 + input3;
        }

        [Cached]
        public static int StaticGetValue(int input1, int input2, int input3, int input4)
        {
            return input1 + input2 + input3 + input4;
        }
    }


    public class TemplateClass : ISampleClass
    {
        private MethodCache _methodCache;

        private static MethodCache _staticMethodCache;

        private MethodCache MethodCache
        {
            get
            {
                if (_methodCache == null)
                    _methodCache = new MethodCache();
                return _methodCache;
            }
        }


        private static MethodCache StaticMethodCache
        {
            get
            {
                if (_staticMethodCache == null)
                    _staticMethodCache = new MethodCache();
                return _staticMethodCache;
            }
        }



        public int GetValue()
        {
            return MethodCache.Invoke(DoGetValue);
        }

        private int DoGetValue()
        {
            return 0;
        }


        public int GetValue(int input)
        {
            return MethodCache.Invoke(DoGetValue, input);
        }

        private int DoGetValue(int input)
        {
            return input;
        }


        public int GetValue(int input1, int input2)
        {
            return MethodCache.Invoke(DoGetValue, input1, input2);
        }

        private int DoGetValue(int input1, int input2)
        {
            return input1 + input2;
        }


        public int GetValue(int input1, int input2, int input3)
        {
            return MethodCache.Invoke(DoGetValue, input1, input2, input3);
        }

        private int DoGetValue(int input1, int input2, int input3)
        {
            return input1 + input2 + input3;
        }


        public int GetValue(int input1, int input2, int input3, int input4)
        {
            return MethodCache.Invoke(DoGetValue, input1, input2, input3, input4);
        }

        private int DoGetValue(int input1, int input2, int input3, int input4)
        {
            return input1 + input2 + input3 + input4;
        }


        public static int StaticGetValue()
        {
            return StaticMethodCache.Invoke(DoGetStaticValue);
        }

        private static int DoGetStaticValue()
        {
            return 0;
        }


        public static int StaticGetValue(int input)
        {
            return StaticMethodCache.Invoke(DoGetStaticValue, input);
        }

        private static int DoGetStaticValue(int input)
        {
            return input;
        }


        public static int StaticGetValue(int input1, int input2)
        {
            return StaticMethodCache.Invoke(DoGetStaticValue, input1, input2);
        }

        private static int DoGetStaticValue(int input1, int input2)
        {
            return input1 + input2;
        }


        public static int StaticGetValue(int input1, int input2, int input3)
        {
            return StaticMethodCache.Invoke(DoGetStaticValue, input1, input2, input3);
        }

        private static int DoGetStaticValue(int input1, int input2, int input3)
        {
            return input1 + input2 + input3;
        }


        public static int StaticGetValue(int input1, int input2, int input3, int input4)
        {
            return StaticMethodCache.Invoke(DoGetStaticValue, input1, input2, input3, input4);
        }

        private static int DoGetStaticValue(int input1, int input2, int input3, int input4)
        {
            return input1 + input2 + input3 + input4;
        }



    }

    [EnableMethodCaching]
    public class SomeService
    {        
        [Cached]
        public int CalculateTheMeaningOfLife()
        {
            //Assume some very time consuming calculations here....
            return 42;
        }
    }

}